package qa.tools.controller;


import cn.hutool.json.JSONObject;
import cn.hutool.json.JSONUtil;
import org.springframework.web.bind.annotation.*;
import qa.tools.commom.ApiResult;
import qa.tools.utils.HuJwtUtils;

import java.util.HashMap;
import java.util.Map;

/**
 * @author Alex
 * @date 2021/9/15 4:26 下午
 * <P></p>
 */
@CrossOrigin
@RestController
// @RequestMapping("/api")
public class UserController {


    @PostMapping("/login")
    public ApiResult login() {

        Map<String, Object> map = new HashMap<>();
        String jwtToken = HuJwtUtils.getJwtToken("1", "1");
        map.put("token", jwtToken);
        map.put("refresh_token", jwtToken);

        return ApiResult.success().setData(map);
    }

    @GetMapping("/userinfo")
    public JSONObject userinfo() {
        String result = "{\"code\":200,\"data\":{\"id\":1,\"name\":\"admin\",\"role\":\"admin\",\"avatar\":\"http://dummyimage.com/48x48/fb0a2a\"},\"avatar\":\"http://dummyimage.com/48x48/fb0a2a\",\"id\":1,\"name\":\"admin\",\"role\":\"visitor\",\"message\":\"获取用户信息成功\"}";
        return JSONUtil.parseObj(result);
    }

    @GetMapping("/menus")
    public ApiResult getMenu(@RequestParam("role") String role) {

        String result = "{\"code\":200,\"message\":\"获取菜单成功\",\"data\":[{\"name\":\"test\",\"title\":\"测试页面\",\"children\":[{\"name\":\"testList\",\"title\":\"列表\"},{\"name\":\"testAdd\",\"title\":\"添加\"},{\"name\":\"testEdit\",\"title\":\"编辑\"},{\"name\":\"testAuth\",\"title\":\"权限测试\"},{\"name\":\"test-cache\",\"title\":\"该页面可缓存\"},{\"name\":\"test-no-cache\",\"title\":\"该页面不可缓存\"},{\"name\":\"nest\",\"title\":\"二级菜单\",\"children\":[{\"name\":\"nestPage1\",\"title\":\"page1\"},{\"name\":\"nestPage2\",\"title\":\"page2\"}]},{\"name\":\"test-error-log\",\"title\":\"测试错误日志\"}]}]}";


        // return JSONUtil.parseObj(result);
        return ApiResult.success();

    }

}
